__file__ = 'A03.py'
__author__ = 'Jerry Liu'
__date__ = '2016-04-13'

"""
    问题：将 0001 题生成的 200 个激活码（或者优惠券）保存到 Redis 非关系型数据库中
    安装pillow库：
    1、http://www.lfd.uci.edu/~gohlke/pythonlibs/下载 redis-2.10.3-py2.py3-none-any.whl
    2、使用命令pip install redis-2.10.3-py2.py3-none-any.whl进行安装
"""

import redis
import random

def save(num):
    r = redis.StrictRedis(host='192.168.74.251', port=6379, db=0)
    for i in range(num):
        choiceCode = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C']
        # 随机生成10个数字
        code = [random.choice(choiceCode) for i in range(10)]
        code = ''.join(code)
        # 保存到redis
        r.lpush('code', code)

    #打印redis的数据
    for i in r.lrange('code', 0, -1):
        print(i)

if __name__ == '__main__':
    save(200)
